package com.hrbxlh.virtualization.controller;

import com.hrbxlh.virtualization.result.Result;
import com.hrbxlh.virtualization.result.ResultEnum;
import com.hrbxlh.virtualization.service.DesktopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author cheer
 */
@RestController
@RequestMapping("/report")
public class ReportController {

    @Autowired
    private DesktopService desktopService;

    /**
     * 判断学生是否有容器文件
     *
     * @param stuorteaId 学生Id
     * @param courseId   课程Id
     * @param chapterId  章节Id
     */
    @RequestMapping(value = "/exists", method = RequestMethod.GET)
    public Result queryStudentFile(String stuorteaId, Integer courseId, Integer chapterId) {
        if(desktopService.isFileExists(stuorteaId, courseId, chapterId)){
            return Result.success();
        } else {
            return Result.error(ResultEnum.CONTAINER_FILE_NOT_EXISTS);
        }
    }

    /**
     * 下载学生容器文件
     *
     * @param stuorteaId 学生Id
     * @param courseId   课程Id
     * @param chapterId  章节Id
     */
    @RequestMapping(value = "/download", method = RequestMethod.GET)
    public void downloadStudentFile(String stuorteaId, Integer courseId, Integer chapterId) {
        desktopService.downloadFile(stuorteaId, courseId, chapterId);
    }
}
